#include "foodcustom.h"
#include <QDebug>
FoodCustom::FoodCustom(QWidget *parent) : QFrame(parent)
{
    initwindow();
}

void FoodCustom::initwindow()
{

    this ->setFrameShape(QFrame::NoFrame);
    this ->setFrameShadow(QFrame::Plain);
    this->resize(660,570);

    foodvlayout1 = new QVBoxLayout(this);
    foodvlayout1->setMargin(0);
    foodvlayout1->setSpacing(0);
    for(int i = 0;i<3;i++)
    {
        foodhlayout[i] = new QHBoxLayout;
        foodhlayout[i]->setMargin(0);
        foodhlayout[i]->setSpacing(0);
    }
     QString foodNamebox[15] = {"蒸羊羔","蒸熊掌","蒸鹿尾儿",\
                             "烧花鸭","烧雏鸡","烧子鹅",\
                             "卤猪","卤鸭","酱鸡",
                             "腊肉","松花小肚儿","晾肉"
                            ,"香肠","什锦苏盘","熏鸡白肚儿"};
    int j = 0;
    int i = 0;
    while(j < 3)
    {
        for( i=0;i<15;i++)
        {
            foodbutton[i] = new FoodButton(foodNamebox [i],"icon/foodmaintain.png","20￥");
            foodbutton[i]->setCheckable(true);
            foodhlayout[j]->addWidget(foodbutton[i]);

            if((i+1)%5 == 0) j++;
            foodvlayout1->addLayout(foodhlayout[j]);
            connect(foodbutton[i],&FoodButton::toggled,[=](){
                if(foodbutton[i]->isChecked())
                {
                   QString foodName =  foodbutton[i]->foodname->text();
                   QString foodMoney = foodbutton[i]->foodmoney->text();
                   emit sendCreatInfo(foodName,foodMoney);
                }
                else if(!foodbutton[i]->isChecked())
                {
                   emit removeInfo();
                }
            });
        }

    }

}



